package com.lcu.student.mapper;

import com.lcu.student.entity.StudentGrades;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;

@Mapper
public interface StudentGradesMapper {

    /**
     * 分页查询
     * @param begin 从第几页开始查
     * @param size 每页查几条数据
     * @return
     */
     List<StudentGrades> selectByPage(@Param("begin") int begin,@Param("size") int size);

    /**
     * 查询总记录数
     * @return
     */
    @Select("SELECT count(*) FROM grades as g,student as s WHERE s.student_number=g.student_number")
    int selectTotalCount();

    /**
     * 带条件的分页查询
     * @param begin 从第几页开始查
     * @param size 每页查几条数据
     * @return
     */
    List<StudentGrades> selectByPage2(@Param("begin") int begin,@Param("size") int size,@Param("studentGrades") StudentGrades studentGrades);

    /**
     * 带条件查询总记录数
     * @return
     */
    int selectTotalCount2(StudentGrades studentGrades);

    /**
     * 添加数据
     * @param studentGrades
     * @return
     */
    void addGrades(StudentGrades studentGrades);

    /**
     * 查询学生学号及姓名
     * @return
     */
    @Select("SELECT DISTINCT student_name FROM student")
    List<StudentGrades> selectStudent();

    /**
     * 查询学生的学号
     * @param studentName
     * @return
     */
    @Select("SELECT student_number FROM student WHERE student_name=#{studentName}")
    List<StudentGrades> selectStudentNumber(@Param("studentName") String studentName);

    /**
     * 根据id删除数据
     * @param id
     */
    @Delete("DELETE FROM grades WHERE grades_id=#{id}")
    int deleteById(int id);

    /**
     * 批量删除
     * @param ids
     * @return
     */
    void deleteByIds(@Param("ids") List<Integer> ids);

    /**
     * 根据id修改数据
     * @param studentGrades
     */
    void updateById(StudentGrades studentGrades);

    /**
     * 根据课程名称查询课程编号
     */
    @Select("select subject_number from subject where subject_name=#{subjectName}")
    String selectSubjectNumber(String subjectName);

    /**
     * 查询所有科目
     * @return
     */
    List<String> selectSubjects();

    /**
     * 查询平均分数据
     * @return
     */
    List<String> selectScores();

    /**
     * 根据科目查找及格人数
     * @param subject
     * @return
     */
    String selectPass(String subject);
}
